<extend name="Base:main" />
<block name="script">
	<link rel="stylesheet" href="__PUBLIC__/seller/css/validform.css" />
        <link rel="stylesheet" href="__PUBLIC__/seller/css/addstyle.css">

        <link rel="stylesheet" href="__PUBLIC__/seller/css/jsstyle.css">
	<script src="__PUBLIC__/seller/js/Validform_v5.3.2.js"></script>
        <style>
		#allmap{margin-left: 24%;height:200px;width:60%;}
		#r-result{width:100%; font-size:14px;}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=SC1n3KjGW9rYZGs5tPqpE7dKQnwfcSU9"></script>
</block>
<block name="content">
    <div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
               购买商品
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="am-active">购买商品</li>
            </ol>
        
            <div class="tpl-portlet-components">
                    <div class="portlet-title">
                      <div class="caption font-green bold">
                        <span class="am-icon-code">订单信息</span>
                        </div>
                    </div>
                    <div class="tpl-block ">
            <form action="" name='myfromSubmit' method="post"  >
                   <input type="hidden" name = "goods_id" id="goods_id" value="{$info['id']}">
                  <input type="hidden"  id="address_id" name="address_id" value="{$address[0]['id']}">
                        
                        <div class="am-g tpl-amazeui-form">
                            <style></style>
                            
                            <div class="address">
                               <div class="am-u-sm-12 am-u-md-12">
                                    <h3>确认收货地址</h3>
                                    <div class="control">
                                            <div class="tc-btn createAddr theme-login am-btn am-btn-danger" id="theme-login">添加地址</div>
                                    </div>
                                    <div class="clear"></div>
                               </div> 
                                <div>
                                        <ul id="add_address">
                                               <volist name="address" id="val">
                                                <div class="per-border"></div>
                                                <li class="user-addresslist <?php if($key == 0):?>defaultAddr<?php endif;?>" address_id="{$val['id']}">

                                                        <div class="address-left">
                                                                <div class="user DefaultAddr">

                                                                        <span class="buy-address-detail">   
                                                                        <span class="buy-user">{$val['truename']} </span>
                                                                        <span class="buy-phone">{$val['phone']}</span>
                                                                        </span>
                                                                </div>
                                                                <div class="default-address DefaultAddr">
                                                                        <span class="buy-line-title buy-line-title-type">收货地址：</span>
                                                                        <span class="buy--address-detail">
                                                           <span class="province">{$val['areaname']}</span>省
                                                                        <span class="street">{$val['address']}</span>
                                                                </div>
                                                              
                                                        </div>
                                                        <div class="address-right">
                                                                <a href="../person/address.html">
                                                                        <span class="am-icon-angle-right am-icon-lg"></span></a>
                                                        </div>
                                                        <div class="clear"></div>

                                                </li>
                                               </volist>
                                        </ul>

                                        <div class="clear"></div>
                                 </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-12">
                  
                                    <table class="am-table am-table-striped am-table-hover table-main">
                                         <tr>
                                            <th width="80px">商品名称</th>
                                            <th width="150">价格</th>
                                            <th width="150px">数量</th>
                                           
                                        </tr>
                                        <tr>
                                            <td>{$info['name']}</td>
                                            <td style="color: red;">￥ 区间价{$info['min_price']}---{$info['max_price']}</td>
                                            <td><button type="button" style="width:25px;height: 25px;" onclick="j_btn()">-</button><input type="text" onkeyup="if( isNaN( this.value ) || this.value > <?php echo $info['stock_num'];?>) { this.value = 1; amount();} else {amount(); }" style="border: 1px solid  !important; width: 30px;text-align:center;-webkit-appearance: none; " id="number" name="number" value="1"><button type="button"   onclick="a_btn();" style="width:25px;height: 25px;">+</button>总库存（{$info['stock_num']}）</td>
                                          
                                        </tr>
                                        
                                    </table>   
                                
                            </div>
                           
                        </div>
                       <div class="am-form-group">
                                <div class="am-u-sm-12 am-u-sm-push-11">
                                   
                                        <button onclick="order_btn()" type="button" class="am-btn am-btn-primary">生成订单</button>
                                </div>
                        </div>
                    </div>
                     </form>
            </div>
    </div>    
    <script>
        function order_btn(){
                       var goods_id = $("#goods_id").val();
                       var address_id = $("#address_id").val();
                       var number = $("#number").val();
                       if(address_id == ''){
                           alert('请选择收货地址');
                           return false;
                       }
                       var _url = getUrl('Goods/order_btn',{'goods_id':goods_id,'address_id':address_id,'number':number});
                        window.location.href = _url;
                     
                   }
    </script>
    <div class="theme-popover-mask"></div>
    <div class="theme-popover " >

				<!--标题 -->
				<div class="am-cf am-padding">
					<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add address</small></div>
				</div>
				<hr/>

				<div class="am-u-md-12 am-u-md-9">
					<form class="am-form am-form-horizontal" id="form1"  onsubmit="return check();" style=" margin-top:20px;">

						<div class="am-form-group">
							<label for="user-email" class="am-form-label" style="width:100px;">收货人</label>
							<div class="am-form-content am-u-sm-8 float_left" style=" margin-left:20px !important">
								<input type="text" name="truename" id="truename" placeholder="收货人">
							</div>
						</div>

						<div class="am-form-group">
							<label for="user-email" class="am-form-label am-u-sm-5" style="width:100px;">手机号码</label>
							<div class="am-form-content am-u-sm-8 float_left" style=" margin-left:20px !important">
								<input id="phone" name="phone" placeholder="手机号必填" type="email">
							</div>
						</div>

						<div class="am-form-group">
							<label for="user-phone" class="am-form-label am-u-sm-3" style="width:100px;">所在地</label>
							<div class="am-form-content am-u-sm-8 address float_left" style=" margin-left:20px !important">
								<select class="data-am-selected " id="city"  onchange="theLocation()" >
                                                                     <volist name="area" id="v">
									<option value="{$v['areaid']}">{$v['areaname']}</option>
                                                                     </volist>
								</select>
							</div>
						</div>

						<div class="am-form-group">
							<label for="user-intro" class="am-form-label am-u-sm-3" style="width:100px;">详细地址</label>
							<div class="am-form-content am-u-sm-8 float_left" style=" margin-left:20px !important">
								<textarea class="" rows="3" id="address" name="address" onBlur = "searchLocation()"  placeholder="输入详细地址"></textarea>
								<small>100字以内写出你的详细地址...</small>
							</div>
						</div>
                                                <div class="am-form-group">
                                                    <div id="allmap"></div>
                                                 </div>
                                                <input id="lng" name="lng" type="hidden" value="{$info.lng}"/>
                                                <input id="lat" name="lat" type="hidden" value="{$info.lat}"/>
						<div class="am-form-group theme-poptit">
							<div class="am-u-sm-9 am-u-sm-push-3">
                                                            <div class="am-btn am-btn-danger" onclick="$(this).submit()" >保存</div>
								<div class="am-btn am-btn-danger close">取消</div>
							</div>
						</div>
					</form>
				</div>

			</div>

			<div class="clear"></div>
    <script>
     
        var stock_num = <?php echo $info['stock_num'];?>;
        var stock = stock_num;
        function j_btn(){
            var num = $("#number").val();
            --num;
            if(num>0){
                $("#number").val(num);
            }
          
        }
        function a_btn(){
            var num = $("#number").val();
            ++num;
            if(num>0 && num<= stock){
                $("#number").val(num);
            }
        }
   
        
        
        //地址添加
        function check(){
            var truename = $("#truename").val();
            var phone = $("#phone").val();
            var city_id = $('#city option:selected') .val();
            var city_name = $('#city option:selected') .text();
            var lng = $("#lng").val();
            var lat = $("#lat").val();
            var address = $("#address").val();
            if(truename == ''){
                alert('请输入收货人名称！');
                return false;
            }
            if(phone == '' || !(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))){
                alert('请输入正确的手机号码！');
                return false; 
            }
            if(address == ''){
                alert('请输入收货人详细地址！');
                return false;
            }
              $.post("{:U('Accunt/address')}",{truename,truename,lng:lng,lat:lat,phone:phone,address:address,city_id:city_id},function(data){
                       if(data.error==1){
                         var str = '';
                             str+='<div class="per-border"></div>';
                             str+='<li class="user-addresslist " address_id="'+data.address_id+'">';
                             str+='          <div class="address-left">';
                             str+='                   <div class="user DefaultAddr">';
                             str+='                          <span class="buy-address-detail">';   
                             str+='                          <span class="buy-user">'+truename+' </span>';
                             str+='                          <span class="buy-phone">'+phone+'</span>';
                             str+='                          </span>';
                             str+='                   </div>';
                             str+='                  <div class="default-address DefaultAddr">';
                             str+='                           <span class="buy-line-title buy-line-title-type">收货地址：</span>';
                             str+='                           <span class="buy--address-detail">';
                             str+='              <span class="province">'+city_name+'</span>省';
                             str+='                           <span class="street">'+address+'</span>';
                             str+='                           </span>';
                             str+='                           </span>';
                             str+='                   </div>';
                             str+='           </div>';
                             str+='           <div class="address-right">';
                             str+='                  <span class="am-icon-angle-right am-icon-lg"></span>';
                             str+='           </div>';
                             str+='   </li>';
                             $("#add_address").append(str);
                             $("#address_id").val(data.address_id);
                             $(document.body).css("overflow","visible");
                            $('#theme-login').removeClass("selected");
                            $('.item-props-can').removeClass("selected");					
                            $('.theme-popover-mask').hide();
                            $('.theme-popover').slideUp(200);
                       }else{
                          alert('添加失败');
                       }
                     
                      },'json');
         
        }
        
        // 弹出地址选择
 
			$(document).ready(function($) {
	
				var $ww = $(window).width();
	
				$('#theme-login').click(function() {
//					禁止遮罩层下面的内容滚动
					$(document.body).css("overflow","hidden");
				
					$(this).addClass("selected");
					$(this).parent().addClass("selected");

									
					$('.theme-popover-mask').show();
					$('.theme-popover-mask').height($(window).height());
					$('.theme-popover').slideDown(200);																		
					
				})
				
				$('.theme-poptit .close,.btn-op .close').click(function() {

					$(document.body).css("overflow","visible");
					$('.theme-login').removeClass("selected");
					$('.item-props-can').removeClass("selected");					
					$('.theme-popover-mask').hide();
					$('.theme-popover').slideUp(200);
				})

				
			}); 
                        
                        //地址选择
				$(function() {
                                        $(document).on('click' , '.user-addresslist',function(){
                                            $("#address_id").val($(this).attr('address_id'));
                                            $(this).addClass("defaultAddr").siblings().removeClass("defaultAddr");
                                        });
                                                theLocation();
				});
                                
                                
                                    	// 百度地图API功能
	var map = new BMap.Map("allmap");   
	setTimeout(function(){
		map.setZoom(14);   
	}, 2000);  //2秒后放大到14级
        
	map.enableScrollWheelZoom(true);
      map.addEventListener("click", showInfo);                  
    </script>
</block>    